package it.accaemme.sgame;



import java.util.Locale;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class Intro extends Activity {
    /** Called when the activity is first created. */
	Resources res;
	TextView how_giocare;
	
	
	public boolean onCreateOptionsMenu(Menu menu){
		getMenuInflater().inflate(R.layout.menu, menu);
		return true;
	}
	public boolean onOptionsItemSelected(MenuItem item){
		Configuration config = new Configuration();
		how_giocare = (TextView) findViewById(R.id.TextView02);
		
		switch (item.getItemId()){
		case R.id.ita_lang_button:
			Toast.makeText(this, "lingua italiana abilitata", 
					Toast.LENGTH_LONG).show();
						
			config.locale = Locale.ITALIAN;
			break;
			
		case R.id.eng_lang_button:
			Toast.makeText(this, "English language abilited", 
					Toast.LENGTH_LONG).show();
			config.locale = Locale.ENGLISH;
			break;
		case R.id.menu_about:
			Toast.makeText(this, res.getString(R.string.about), 
				Toast.LENGTH_LONG).show();
			return true;
		}
		

		
		getBaseContext().getResources().updateConfiguration(config, 
			      getBaseContext().getResources().getDisplayMetrics());

		getResources().updateConfiguration(config, null);
		//this.setContentView(R.layout.intro);
		how_giocare.setText( res.getString(R.string.come_giocare) );
		
		return super.onOptionsItemSelected(item);
	}
	
    public void onCreate(Bundle savedInstanceState) {
    	res = getResources();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intro);

    	final TextView tw_livello = (TextView) this.findViewById(R.id.textViewProgress);
        
        final EditText nplayers = (EditText)this.findViewById(R.id.nPlayers);
        nplayers.setHint("2");
        
        final SeekBar level = (SeekBar) findViewById(R.id.seekBar1);
        OnSeekBarChangeListener MySeekBarListener = new OnSeekBarChangeListener() {
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            	int progress = level.getProgress();
				if(progress==0) tw_livello.setText(res.getString(R.string.livello_selezionato) + ": " + String.valueOf(progress) + " - EASY");
            	if(progress==1) tw_livello.setText(res.getString(R.string.livello_selezionato) + ": " + String.valueOf(progress) + " - MIDDLE");
            	if(progress==2) tw_livello.setText(res.getString(R.string.livello_selezionato) + ": " + String.valueOf(progress) + " - HARD");
            	if(progress==3) tw_livello.setText(res.getString(R.string.livello_selezionato) + ": " + String.valueOf(progress) + " - MIXxX");    
            	
                    
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            		tw_livello.setText(res.getString(R.string.scorri_livello));
            }

            @Override
            public void onProgressChanged(SeekBar seekBark, int progress, boolean fromUser) {
            	if(progress==0) tw_livello.setText(res.getString(R.string.livello) + ": " + String.valueOf(progress) + " - EASY");
            	if(progress==1) tw_livello.setText(res.getString(R.string.livello) + ": " + String.valueOf(progress) + " - MIDDLE");
            	if(progress==2) tw_livello.setText(res.getString(R.string.livello) + ": " + String.valueOf(progress) + " - HARD");
            	if(progress==3) tw_livello.setText(res.getString(R.string.livello) + ": " + String.valueOf(progress) + " - MIXxX");
            }
         };
         level.setOnSeekBarChangeListener(MySeekBarListener);


        
        
        ImageButton button = (ImageButton) findViewById(R.id.imageButton1);
        
        
        button.setOnClickListener(new OnClickListener(){
        	public void onClick(View arg0){
        		int n = 2;
                try{
                	//if(temp.matches("/^\d+$/"))
                		n = Integer.valueOf(nplayers.getText().toString());
                }
                catch (NumberFormatException nfe) {
                	  System.out.println("Could not parse " + nfe);
        		}	
        		
        		
                	Intent entra = new Intent(Intro.this, SGame.class);
                	String pkg=getPackageName(); 
                	entra.putExtra(pkg+".giocatori", n);
                	entra.putExtra(pkg+".livello", level.getProgress());
                	Intro.this.startActivity(entra);
                }
        });
    
    }
}